package cn.bj.yu.add;

import java.util.concurrent.CountDownLatch;

/**
 * @author 周宇
 * @create 2020-08-13 11:23
 * 减法计数器
 */
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        // 总数是6 倒计时操作
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + " Go out");
                countDownLatch.countDown(); //数量 -1
            }, String.valueOf(i)).start();
        }

        countDownLatch.await();//等待计数器归零 然后在向下执行

        //关门
        System.out.println("close door");
    }
}